package com.member.spring_cloud_member;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.member.entity.Goods;

@RestController
public class ChartController {

	private List<Goods> chartList;
	private static List<Goods> goodsList=new ArrayList<>();
	
	@RequestMapping(value="/goods",method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
	public List<Goods> getAllGoods(){
		setAllGoodsList();
		return goodsList;
	}
	
	@RequestMapping(value="/id/{id}",method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
	public Goods addOneGoodsInChart(@PathVariable("id") Integer id){
		for(Goods goods:goodsList){
			if(id.equals(goods.getG_id())){
				return goods;
			}
		}
		return null;
	}
	
	
	
	private static void setAllGoodsList(){
		goodsList.add(new Goods(1, "book1", 1));
		goodsList.add(new Goods(2,"book2",2));
		goodsList.add(new Goods(3, "book3", 3));
	}
	
	
	
	
	
	
	
}
